module.exports = function ($scope, $state, $resource,$modalInstance, $modal, toaster,item,flag ,FileUploader){

        $scope.tourbase = {};
        var code =  flag ? {'flag': true} : item;
        $scope.tourbase = {
            'code':code
        };
        
        init();
        function init(){
           
            // $scope.tourbase = flag ? {'flag': true} : {'code':angular.copy(item)};
            
           
            $resource('/api/as/goc/tourbase/getInfo', {}, {}).save({'code': $scope.tourbase.code},function (res) {
    
                // if (res.errcode !== 0) {
                //     alert("数据获取失败");
                //     return;
                // }
                
                if (res.errcode == 0) {
                    $scope.tourbase = res.data;
                }
    
            });

            // $scope.search();
         }
        
        // 上传图片
        var uploader1 = $scope.uploader1 = new FileUploader({
            url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
        });
        
        uploader1.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });  
        //封面图片 
        uploader1.onSuccessItem = function(fileItem, response, status, headers) {
            $scope.tourbase.image_top = response.savename; 
        };
        var uploader2 = $scope.uploader2 = new FileUploader({
            url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
        });
        
        uploader2.filters.push({
            name: 'imageFilter',
            fn: function(item /*{File|FileLikeObject}*/, options) {
                var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        });    
        uploader2.onSuccessItem = function(fileItem, response, status, headers) {
            $scope.tourbase.image_arr = response.savename; 
        };
       

        $scope.save = function(){
            if($scope.tourbase.product_manage_ecommend_arr == undefined){
                toaster.error({title: '', body: '请输入产品特色！'});
              return;
            }
            if($scope.tourbase.with_group_terms == undefined){
                toaster.error({title: '', body: '请输入跟团条款！'});
              return;
            }
            if($scope.tourbase.terms_type == undefined){
                toaster.error({title: '', body: '请选择退改说明！'});
              return;
            }
            if($scope.tourbase.departure_mode == undefined){
                toaster.error({title: '', body: '请选择出发方式！'});
              return;
            }
            if($scope.tourbase.return_mode == undefined){
                toaster.error({title: '', body: '请选择返程方式！'});
              return;
            }
            if($scope.tourbase.image_top == undefined){
                toaster.error({title: '', body: '请上传首图！'});
              return;
            }
            if($scope.tourbase.image_arr == undefined){
                toaster.error({title: '', body: '请上传封面图片！'});
              return;
            }
            $resource('/api/as/goc/tourbase/saveInfo', {}, {}).save($scope.tourbase,function (res) {
               
                if(res.errcode === 0){
                    toaster.success({title: '', body: '保存成功'});
                    $modalInstance.close();
                }else{
                    toaster.error({title: '', body: res.errmsg});
                }
                   
            });
        }
         
    }